package com.me.testcustomview;

import org.json.JSONException;
import org.json.JSONObject;

import android.R.color;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageButton;

public class SubjectButton extends ImageButton {
	private JSONObject data;
	private String subjectId;
	private String subjectName;
	private String imageName;
	private Context mContext;

	public SubjectButton(Context context) {
		super(context);
		this.mContext = context;
		this.setBackgroundColor(color.transparent);
	}
	
	public SubjectButton(Context context, AttributeSet attr, int arg) {
		super(context, attr, arg);
		this.mContext = context;
		this.setBackgroundColor(color.transparent);
	}
	
	public SubjectButton(Context context, AttributeSet attr){
		super(context, attr);
		this.mContext = context;
		this.setBackgroundColor(color.transparent);
	}

	public SubjectButton(Context context, JSONObject data) {
		super(context);
		this.mContext = context;
		this.data = data;
		this.setBackgroundColor(color.transparent);
		setData(data);
	}
	

	public String getSubjectId() {
		return subjectId;
	}

	public void setSubjectId(String subjectId) {
		this.subjectId = subjectId;
	}

	public String getSubjectName() {
		return subjectName;
	}

	public void setSubjectName(String subjectName) {
		this.subjectName = subjectName;
	}

	public String getSubjectImageName() {
		return imageName;
	}

	public void setSubjectImageName(String imageName) {
		this.imageName = imageName;
		this.setImageDrawable(getResources().getDrawable(getResources().getIdentifier(imageName, "drawable", mContext.getPackageName())));
	}
	
	public void setData(JSONObject subjectData){
		this.data = subjectData;
	try {
		setSubjectId(subjectData.getString("id"));
		setSubjectName(subjectData.getString("name"));
		setSubjectImageName(subjectData.getString("image"));
	} catch (JSONException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	}
	
	public JSONObject getData(){
		return this.data;
	}

}
